﻿Imports TMySQL
Public Class frmInnoDBStatus
    Implements ITabForm
    Private _MyInnoDBStatus As TMyInnoDBStatus
    Public Sub New()
        ' この呼び出しは、Windows フォーム デザイナで必要です。
        InitializeComponent()
        ' InitializeComponent() 呼び出しの後で初期化を追加します。
        _MyInnoDBStatus = New TMyInnoDBStatus(frmMain.Connection)
        frmMain.EditorSettings.Apply(txtAll)
        frmMain.EditorSettings.Apply(txtBackGroundThread)
        frmMain.EditorSettings.Apply(txtBufferPoolAndMemory)
        frmMain.EditorSettings.Apply(txtFileIO)
        frmMain.EditorSettings.Apply(txtInsertBufferAndAdaptiveHashIndex)
        frmMain.EditorSettings.Apply(txtLog)
        frmMain.EditorSettings.Apply(txtRowOperations)
        frmMain.EditorSettings.Apply(txtSemaphores)
        frmMain.EditorSettings.Apply(txtTransactions)
    End Sub

    Public ReadOnly Property ActiveEditor() As Sgry.Azuki.WinForms.AzukiControl
        Get
            Select Case pgc.SelectedTab.Name
                Case "tbsAll"
                    Return txtAll
                Case "tbsBackGroundThread"
                    Return txtBackGroundThread
                Case "tbsBufferPoolAndMemory"
                    Return txtBufferPoolAndMemory
                Case "tbsFileIO"
                    Return txtFileIO
                Case "tbsInsertBufferAndAdaptiveHashIndex"
                    Return txtInsertBufferAndAdaptiveHashIndex
                Case "tbsLog"
                    Return txtLog
                Case "tbsRowOperations"
                    Return txtRowOperations
                Case "tbsSemaphores"
                    Return txtSemaphores
                Case "tbsTransactions"
                    Return txtTransactions
                Case Else
                    Return Nothing
            End Select
        End Get
    End Property

    Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        Cursor.Current = Cursors.WaitCursor
        Try
            ShowResult()
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub

    Private Sub ShowResult()
        _MyInnoDBStatus.Refresh()
        txtAll.Text = _MyInnoDBStatus.Result
        txtBackGroundThread.Text = _MyInnoDBStatus.BackGroundThread
        txtBufferPoolAndMemory.Text = _MyInnoDBStatus.BufferPoolAndMemory
        txtFileIO.Text = _MyInnoDBStatus.FileIO
        txtInsertBufferAndAdaptiveHashIndex.Text = _MyInnoDBStatus.InsertBufferAndAdaptiveHashIndex
        txtLog.Text = _MyInnoDBStatus.Log
        txtRowOperations.Text = _MyInnoDBStatus.RowOperations
        txtSemaphores.Text = _MyInnoDBStatus.Semaphores
        txtTransactions.Text = _MyInnoDBStatus.Transactions
    End Sub

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        If SaveDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            Cursor.Current = Cursors.WaitCursor
            Try
                SaveResult(SaveDlg.FileName)
                Call MsgBox("保存しました", MsgBoxStyle.Information)
            Finally
                Cursor.Current = Cursors.Default
            End Try

        End If
    End Sub
    Private Sub SaveResult(ByVal AFileName As String)
        Dim sw As New System.IO.StreamWriter(AFileName, False, System.Text.Encoding.UTF8)
        Try
            sw.Write(Me.ActiveEditor.Text)
            sw.Flush()
        Finally
            sw.Close()
        End Try
    End Sub
End Class